package killerqueen.game.objects;

import java.util.ArrayList;

import java.util.List;

import killerqueen.game.interfaces.GameObject;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;

public class Curve implements GameObject {

  private List<PolygonShape> edges;
  private Body body;
  private float x;

  public Curve() {
  }

  @Override
  public void init(World world, String id) {
    edges = new ArrayList<PolygonShape>();
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(0, 0);
    body = world.createBody(bodyDef);

    for (int i = 0; i < 100; i++) {
      float aux = x + 0.5f;
      PolygonShape edge = new PolygonShape();
      edge.setAsEdge(new Vec2(x, (float) Math.sin(x) + 10), new Vec2(aux, (float) Math.sin(aux) + 10));
      edges.add(edge);
      body.createFixture(edge, 0);
      x = aux;
    }
  }

  @Override
  public void input(Input input) {
    // TODO Auto-generated method stub

  }

  @Override
  public void paint(Graphics g) {

    g.pushTransform();

    Vec2 pos = body.getPosition();
    float angle = body.getAngle();
    g.translate(pos.x, pos.y);
    g.rotate(0, 0, (float) Math.toDegrees(+angle));
    g.setColor(Color.green);
    for (PolygonShape edge : edges) {
      g.drawLine(edge.getVertex(0).x, edge.getVertex(0).y, edge.getVertex(1).x, edge.getVertex(1).y);
    }

    g.popTransform();

  }

  @Override
  public void update(long delta) {
    return;

  }


public void setX(float x) {
	this.x = x;
}

@Override
public void destroy(World world) {
	// TODO Auto-generated method stub
	
}
}